<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class:{'jee-hidden': disableSubmit} }"
    @cancel="handleCancel"
    cancelText="关闭">
    <goods-form ref="realForm" @ok="submitCallback" :disabled="disableSubmit" :title="title"></goods-form>
  </j-modal>
</template>

<script>

  import GoodsForm from './GoodsForm'
  export default {
    name: 'GoodsModal',
    components: {
      GoodsForm
    },
    data () {
      return {
        title:'',
        width:1000,
        visible: false,
        disableSubmit: false
      }
    },
    methods: {
      add () {
        this.visible=true
        this.$nextTick(()=>{
          this.$refs.realForm.add();
        })
      },
      edit (record) {
        this.visible=true

        this.$nextTick(()=>{
          this.$refs.realForm.isEditForm = true
          this.$refs.realForm.show_guige = false
          this.$refs.realForm.edit(record);
          this.$refs.realForm.setTableColumnsEdit(record.goodsSpecsList);
          console.log(this.$refs.realForm.isEditForm)
        })
      },
      close () {
        /*this.$refs.realForm.show_guige = false
        this.$refs.realForm.linshiarr = []//重置缓存数组
        this.$refs.realForm.dataSource = []//重置表格数据
        this.$refs.realForm.columns = []//重置表头设置*/

        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        this.$refs.realForm.submitForm();

      },
      submitCallback(){
        this.$refs.realForm.show_guige = false
        this.$refs.realForm.linshiarr = []//重置缓存数组
        this.$refs.realForm.dataSource = []//重置表格数据
        this.$refs.realForm.columns = []//重置表头设置
        this.$emit('ok');
        this.visible = false;
      },
      handleCancel () {
        this.$refs.realForm.show_guige = false
        this.$refs.realForm.linshiarr = []  //重置缓存数组
        this.$refs.realForm.dataSource = []  //重置表格数据
        this.$refs.realForm.columns = []   //重置表头设置
        this.$refs.realForm.isEditForm = false
        this.close()
      }
    }
  }
</script>